home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / ^Php / php album / VERSION2 / ALBUM.PHP next >
Encoding:
PHP Script  |  2001-02-18  |  2.5 KB  |  88 lines

  1. <?php
  2.     /* album.php - version 2
  3.      * .net magazine (www.netmag.co.uk), issue 83
  4.      * Matt Kynaston, 2001
  5.      * Distributed under the GNU Public License - www.gnu.org/copyleft/gpl.html
  6.      *
  7.      * This version of the PHP Photo Album dynamically creates thumbnails from the files
  8.      * uploaded to the 'photos' directory. It gives the user the opportunity to upload 
  9.      * their own photos to the album. It requires thumbnail.php to be in the same 
  10.      * directory as it.
  11.      *
  12.      * Also requires PHP4 with the GD and ZLIB extensions installed (php_gd.dll and
  13.      * php_zlib.dll on Windows). These are available from the full download of PHP at
  14.      * www.php.net. Modify your php.ini file (C:\WINDOWS\PHP.INI in Windows systems) to 
  15.      * point at them.
  16.     */
  17. ?>
  18. <html>
  19. <head>
  20. <title>Photo Album</title>
  21. </head>
  22.  
  23. <body bgcolor="#FFFFFF" text="#000000">
  24. <h1>PHP Photo Album</h1>
  25. <h3>(slow version)</h3>
  26.  
  27. <?php
  28.     // if file has been posted, copy to photo directory
  29.     if (isset($ulFile) && $ulFile_name) {
  30.         if (copy($ulFile, "photos/$ulFile_name")) {
  31.             print "<p>$ulFile_name successfully uploaded</p>\n";
  32.         } else {
  33.             print "<p>Oops! Couldn't upload $ulFile_name</p>\n";
  34.         }
  35.         unlink($ulFile);
  36.     }    
  37. ?>
  38.  
  39.  
  40. <form name="form1" method="post" action="<?php print $PHP_SELF?>" enctype="multipart/form-data">
  41.   <p>Add your own image to the album:<br>
  42.     <input type="file" name="ulFile">
  43.   </p>
  44.   <p>
  45.     <input type="submit" name="Submit" value="Submit">
  46.   </p>
  47. </form>
  48.  
  49. <p> </p>
  50. <table width="100%" border="0" cellspacing="10">
  51.     <tr align="center">
  52.     <?php
  53.         // this section generates table rows filled with images
  54.         $num_cols = 4;
  55.         $dirname = "photos";
  56.         
  57.         $col = 0;
  58.         $dh = opendir( $dirname ); // open directory for reading
  59.         
  60.         // loop through all files in photo directory, reading filename into $file
  61.         while($file=readdir($dh)) { 
  62.             if ($file=="." || $file=="..") continue; // ignore directory files
  63.             
  64.             /* notice the image source: our PHP thumbnail creator, with
  65.              * the name of the file to create a thumnail for passed in the query string 
  66.             */
  67.             print "<td valign=middle><a href='$dirname/$file' target='_blank'><img src='thumbnail.php?file=$dirname/$file' border=0>";
  68.             print "<br>$file</a></td>\n";
  69.             $col++;
  70.             
  71.             // if max number of columns reached, start new row
  72.             if ($col==$num_cols) {
  73.                 print "</tr>\n<tr align=center>\n";
  74.                 $col=0;
  75.             }
  76.         }
  77.         
  78.         // fill rest of row with empty cells
  79.         for ($i=$col;$i<$num_cols;$i++) {
  80.             print "<td></td>\n";
  81.         }
  82.     ?>
  83.     </tr>
  84. </table>
  85.  
  86. </body>
  87. </html>
  88.